
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def convertBST(self, root) :
        def dst(root):
            nonlocal temp
            if not root:
                return
            dst(root.right)
            temp = temp +root.val
            root.val = temp
            dst(root.left)

        temp = 0
        dst(root)
        return root






